<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="utf-8">
    <meta content="width=device-width, initial-scale=1, shrink-to-fit=no" name="viewport">
    <title>用户中心</title>
    <link rel="stylesheet" th:href="@{/frame/vendors/mdi/css/materialdesignicons.min.css}">
    <link rel="stylesheet" th:href="@{/frame/vendors/base/vendor.bundle.base.css}">
    <link rel="stylesheet" th:href="@{/css/style.css}">
    <link rel="shortcut icon" th:href="@{/images/favicon.png}"/>
</head>

<body>
<div class="container-scroller">


    <nav class="navbar col-lg-12 col-12 p-0 fixed-top d-flex flex-row">
        <div class="navbar-brand-wrapper d-flex justify-content-center">
            <div class="navbar-brand-inner-wrapper d-flex justify-content-between align-items-center w-100">
                <a class="navbar-brand brand-logo" th:href="@{/index}">
                    <h1>
                        <span class="display-4" th:text="${session.user.getUserName()}+'欢迎!'"></span>
                    </h1>
                </a>
                <button class="navbar-toggler navbar-toggler align-self-center" data-toggle="minimize" type="button">
                    <span class="mdi mdi-sort-variant"></span>
                </button>
            </div>
        </div>
        <div class="navbar-menu-wrapper d-flex align-items-center justify-content-end">
            <ul class="navbar-nav navbar-nav-right">
                <li class="nav-item nav-profile dropdown">
                    <a class="nav-link dropdown-toggle" data-toggle="dropdown" href="#" id="profileDropdown">
                        <img alt="profile" th:src="@{/img/head.jpg}">
                        <span class="nav-profile-name" th:text="${session.user.getUserName()}"></span>
                    </a>
                    <div aria-labelledby="profileDropdown" class="dropdown-menu dropdown-menu-right navbar-dropdown">
                        <a class="dropdown-item" th:href="@{/user/setting}">
                            <i class="mdi mdi-settings text-primary"></i>
                            设置
                        </a>
                        <a class="dropdown-item" th:href="@{/loginout}">
                            <i class="mdi mdi-logout text-primary"></i>
                            登出
                        </a>
                    </div>
                </li>
            </ul>
            <button class="navbar-toggler navbar-toggler-right d-lg-none align-self-center" data-toggle="offcanvas"
                    type="button">
                <span class="mdi mdi-menu"></span>
            </button>
        </div>
    </nav>
    <div class="container-fluid page-body-wrapper">
        <nav class="sidebar sidebar-offcanvas" id="sidebar">
            <ul class="nav">
                <li class="nav-item">
                    <a class="nav-link" th:href="@{/index}">
                        <i class="mdi mdi-home menu-icon"></i>
                        <span class="menu-title">主页</span>
                    </a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" th:href="@{/user/bindcenter}">
                        <i class="mdi mdi-view-headline menu-icon"></i>
                        <span class="menu-title">设备绑定中心</span>
                    </a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" th:href="@{/user/cars}">
                        <i class="mdi mdi-grid-large menu-icon"></i>
                        <span class="menu-title">设备中心</span>
                    </a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" th:href="@{/user/setting}">
                        <i class="mdi mdi-account menu-icon"></i>
                        <span class="menu-title">用户中心</span>
                    </a>
                </li>
            </ul>
        </nav>
        <div class="main-panel">
            <div class="content-wrapper">
                <div class="row">
                    <div class="col-12 grid-margin">
                        <div class="card">
                            <div class="card-body">
                                <h4 class="card-title">信息中心</h4>
                                <form class="form-sample" id="info" onsubmit="return false;">
                                    <p class="card-description">
                                        信息展示设置中心
                                    </p>
                                    <div class="row">
                                        <div class="col-md-4">
                                            <div class="form-group row">
                                                <label class="col-sm-3 col-form-label">姓名</label>
                                                <div class="col-sm-9">
                                                    <input class="form-control" id="userName" name="userName"
                                                           th:value="${user.getUserName()}"
                                                           type="text"/>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="col-md-4">
                                            <div class="form-group row">
                                                <label class="col-sm-3 col-form-label">性别</label>
                                                <div class="col-sm-9">
                                                    <select class="form-control" id="sex" name="sex">
                                                        <option th:selected="${user.getSex() == 1}" value="1">男</option>
                                                        <option th:selected="${user.getSex() == 0}" value="0">女</option>
                                                    </select>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="col-md-4">
                                            <div class="form-group row">
                                                <label class="col-sm-3 col-form-label">密码</label>
                                                <div class="col-sm-9">
                                                    <input class="form-control" id="passWord"
                                                           name="passWord" th:value="${user.getPassWord()}"
                                                           type="password"/>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="row">
                                        <div class="col-md-6">
                                            <div class="form-group row">
                                                <label class="col-sm-3 col-form-label">手机号码</label>
                                                <div class="col-sm-9">
                                                    <input class="form-control" id="phone" name="phone"
                                                           th:value="${user.getPhone()}"
                                                           type="text"/>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="row">
                                        <div class="col-md-4">
                                            <div class="form-group row">
                                                <label class="col-sm-3 col-form-label">省份</label>
                                                <div class="col-sm-9">
                                                    <select class="form-control" id="province" name="province">
                                                        <option value="110000">北京市</option>
                                                        <option value="120000">天津市</option>
                                                        <option value="130000">河北省</option>
                                                        <option value="140000">山西省</option>
                                                        <option value="150000">内蒙古自治区</option>
                                                        <option value="210000">辽宁省</option>
                                                        <option value="220000">吉林省</option>
                                                        <option value="230000">黑龙江省</option>
                                                        <option value="310000">上海市</option>
                                                        <option value="320000">江苏省</option>
                                                        <option value="330000">浙江省</option>
                                                        <option value="340000">安徽省</option>
                                                        <option value="350000">福建省</option>
                                                        <option value="360000">江西省</option>
                                                        <option value="370000">山东省</option>
                                                        <option value="410000">河南省</option>
                                                        <option value="420000">湖北省</option>
                                                        <option value="430000">湖南省</option>
                                                        <option value="440000">广东省</option>
                                                        <option value="450000">广西壮族自治区</option>
                                                        <option value="460000">海南省</option>
                                                        <option value="500000">重庆市</option>
                                                        <option value="510000">四川省</option>
                                                        <option value="520000">贵州省</option>
                                                        <option value="530000">云南省</option>
                                                        <option value="540000">西藏自治区</option>
                                                        <option value="610000">陕西省</option>
                                                        <option value="620000">甘肃省</option>
                                                        <option value="630000">青海省</option>
                                                        <option value="640000">宁夏回族自治区</option>
                                                        <option value="650000">新疆维吾尔自治区</option>
                                                        <option value="710000">台湾省</option>
                                                        <option value="810000">香港特别行政区</option>
                                                        <option value="820000">澳门特别行政区</option>
                                                    </select>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="col-md-4">
                                            <div class="form-group row">
                                                <label class="col-sm-3 col-form-label">城市</label>
                                                <div class="col-sm-9">
                                                    <select class="form-control" id="city" name="city">
                                                    </select>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="col-md-4">
                                            <div class="form-group row">
                                                <label class="col-sm-3 col-form-label">区域</label>
                                                <div class="col-sm-9">
                                                    <select class="form-control" id="region" name="region">
                                                        <option selected="selected" value="0">无</option>
                                                    </select>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <button class="btn btn-primary mr-2" id="submit" type="submit">提交</button>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</div>
<script th:src="@{/frame/vendors/base/vendor.bundle.base.js}"></script>
<script th:src="@{/frame/vendors/datatables.net/jquery.dataTables.js}"></script>
<script th:src="@{/frame/vendors/datatables.net-bs4/dataTables.bootstrap4.js}"></script>
<script th:src="@{/js/off-canvas.js}"></script>
<script th:src="@{/js/hoverable-collapse.js}"></script>
<script th:src="@{/js/template.js}"></script>
<script th:src="@{/js/dashboard.js}"></script>
<script th:src="@{/js/data-table.js}"></script>
<script th:src="@{/js/jquery.dataTables.js}"></script>
<script th:src="@{/js/dataTables.bootstrap4.js}"></script>
<script th:src="@{/layuiadmin/layui/layui.js}"></script>
<script>
    layui.config({
        base: '/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['layer'], function () {
        var $ = layui.$
            , layer = layui.layer;

        //对手机号码进行检查
        function ReCheck(element, re, tips) {
            if (!re.test($(element).val())) {
                layer.msg("[提示]" + tips);
                return false;
            }
            return true;
        }

        function LengthCheck(element, minLength, maxLength, tips) {
            let e = $(element).val()
            if (!(e.length >= minLength && e.length <= maxLength)) {
                layer.msg("[提示]" + tips);
                return false;
            }
            return true;
        }

        function changecity() {
            $.ajax({
                type: 'post',
                url: '/user/getcity',
                data: $("#province").serialize(),
                success: function (data) {
                    $("#city").empty();
                    for (let index = 0; index < data.length; index++)
                        $("#city").append($("<option value=" + data[index].code + ">" + data[index].name + "</option>"));
                }
            })

        }

        changecity()
        $("#province").change(() => {
            changecity()
        })
        $("#city").change(() => {
            $.ajax({
                type: 'post',
                url: '/user/getregion',
                data: $("#city").serialize(),
                success: function (data) {
                    $("#region").empty();
                    for (let index = 0; index < data.length; index++)
                        $("#region").append($("<option value=" + data[index].code + ">" + data[index].name + "</option>"));
                }
            })
        })
        $("#submit").click(() => {
            let regPhone = /^[1][3,4,5,7,8,9][0-9|*]{9}$/;
            let regPassWord = /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,16}$/;
            if (!LengthCheck("#userName", 2, 6, "请输入正确的用户名！") ||
                !LengthCheck("#passWord", 8, 16, "密码长度为8-16位之间！") ||
                !LengthCheck("#phone", 11, 11, "手机号长度不正确！") ||
                !LengthCheck("#emergencyPhone", 11, 11, "紧急联系人手机号长度不正确！") ||
                !ReCheck("#phone", regPhone, "手机号规则不正确！") ||
                !ReCheck("#passWord", regPassWord, "密码必须包含字母和数字，且在6~18位之间！"))
                return;
            let data = decodeURIComponent($("#info").serialize());
            $.ajax({
                type: 'post',
                url: '/user/infochange',
                data: data,
                success: function (Msg) {
                    if (Msg.code != 200) {
                        layer.msg(Msg.msg);
                    } else {
                        layer.msg("更新用户信息成功");
                    }
                }
            })
        })

    })
</script>
</body>
</html>
